package com.example.ex_3;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    TextView show;
    Button bn, bn2, bn4, bn5, bn6, bn7, bn8;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        show = (TextView) findViewById(R.id.textView);
        bn = (Button) findViewById(R.id.button);
        bn.setOnClickListener(this);
        bn2 = (Button) findViewById(R.id.button2);
        bn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                show.setText("点击了采用匿名内部类作为监听器的按钮");
            }
        });
        bn7 = (Button) findViewById(R.id.button7);
        bn7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MainActivity.this, Activity2.class);
                startActivity(i);
            }
        });
        bn8 = (Button) findViewById(R.id.button8);
        bn8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MainActivity.this, Activity3.class);
                startActivity(i);
            }
        });
        setClickListener();//调用内部类
        bn5=(Button)findViewById(R.id.button5);
        bn5.setOnClickListener(new MyClick (show));
    }
    @Override
    public void onClick(View v) {
        show.setText("点击了采用activity作为监听器的按钮");
    }

    public void clickHandler(View source) {
        TextView show = (TextView) findViewById(R.id.textView);
        show.setText("点击了绑定到标签作为监听器的按钮");
    }
    public void setClickListener() {
        bn4=(Button)findViewById(R.id.butt4);
        bn4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                show.setText("点击了采用内部类作为监听器的按钮");
            }
        });
    }
}
class MyClick implements View.OnClickListener {
    private TextView textView;
    //把文本框作为参数传入
    public MyClick(TextView textView) {
        this.textView=textView;
    }

    @Override
    public void onClick(View v) {
        textView.setText("点击了采用外部类作为监听器的按钮");
    }
}
